package shoppingmall.reception.dto;

import lombok.Data;

@Data
public class Result {
    private Integer code;  //响应码:200代表成功，400客户端请求语法错误，401请求未经授权，404请求资源不存在，500服务器错误
    private String message;  //响应信息，描述字符串
    private Object result;  //返回的数据

    public Result() {
    }

    public Result(Integer code, String message, Object result) {
        this.code = code;
        this.message = message;
        this.result = result;
    }


    /**
     * 成功响应
     *
     * @return
     */
    public static Result success() {
        return new Result(200, "success", null);
    }

    public static Result success(Object result) {
        return new Result(200, "success", result);
    }

    /**
     * 失败响应
     *
     * @param msg
     * @return
     */
    public static Result error() {
        return new Result(404, "请求资源不存在!", null);
    }

    public static Result error(String message) {
        return new Result(400, message, null);
    }

    public static Result error(Integer code, String message) {
        return new Result(code, message, null);
    }
}